<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>php端验证--闫海的个人博客-芒果小叨</title>
<meta name="keywords" content="个人博客,闫海个人博客,php端验证" />
<meta name="description" content="thinkphp自动验证处理方法." />
<link href="/Public/Index/css/base.css" rel="stylesheet">
<link href="/Public/Index/css/new.css" rel="stylesheet">
<link rel="stylesheet" href="/Public/Index/css/animate.css">
<link rel="stylesheet" type="text/css" href="/Public/Admin/ueditor/third-party/SyntaxHighlighter/shCoreDefault.css">
<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script><script type="text/javascript">uaredirect("http://yanhai0531.com/mobile.php");</script>
<!--[if lt IE 9]>
<script src="/Public/Index/js/modernizr.js"></script>
<![endif]-->

<script type="text/javascript" src="/Public/Admin/Js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/Public/Admin/ueditor/third-party/SyntaxHighlighter/shCore.js"></script>
<script type="text/javascript">
  SyntaxHighlighter.all();
</script>
<script type="text/javascript">
  var url = '/index/article';
  $(function(){
    var id = '26';
    $.post(url+'/addClick',{'id':id},function(data){
        $("#pclick").html('点击数：' + data);
    });
  })
</script>
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F5a97c6527b57694be765111b6a23bffc' type='text/javascript'%3E%3C/script%3E"));
</script>
</head>
<body>
<script src="/Public/Index/js/jquery.js"></script>
<div class='header animated bounceInDown'>
    <div class='wrap'>
      <div class='logo'><a data-scroll-reveal='enter from the top over 0.7s' href='/'>
         <img src='/Public/Index/images/logo.png' title='闫海的个人博客首页' alt="logo" /></a>
      </div>
      <div data-scroll-reveal='enter from the top over 0.7s' class='top-nav'>
          <ul id="topnav">
            <li><a href='/'  title='首页'>首页<span></span></a></li>
            <li><a href='/index/list/2.html' title='关于我'>关于我<span> </span></a></li><li><a href='/index/list/3.html' title='时光轴'>时光轴<span> </span></a></li><li><a href='/index/list/1.html' title='品味人生'>品味人生<span> </span></a></li><li><a href='/index/list/5.html' title='技术分享'>技术分享<span> </span></a></li>            <li><a href='/index/article/message.html'  title='给我留言'>给我留言<span></span></a></li>
          </ul>
      </div>
      <div class='clear'></div>
    </div>
</div>
<article class="blogs">
  <h1 class="t_nav">
  	<span>您当前的位置：<a href="/index.html">首页</a>&nbsp;&gt;&nbsp;
	<a href="/index/list/5.html">技术分享</a>
	&nbsp;&gt;&nbsp;<a href="/index/list/10.html">php</a>
	
  	</span>  <a href="/index.html" class="n1">网站首页</a>
  </h1>
  <div class="index_about">
    <h2 class="c_titile">php端验证</h2>
    <p class="box_c"><span class="d_time">发布时间：2015-01-04 15:06</span><span>编辑：小叨</span><span id="pclick">点击数：149</span></p>
    <ul class="infos" style="word-break: break-all;">
      <pre class="brush:php;toolbar:false;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//此处省略...
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//注册表单处理
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;register(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$this-&gt;isPost())&nbsp;halt(&#39;页面不存在&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($_SESSION[&#39;verify&#39;]&nbsp;!=&nbsp;I(&#39;post.verify&#39;,&#39;&#39;,&#39;md5&#39;)){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;error(&#39;验证码错误&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$db&nbsp;=&nbsp;D(&#39;User&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$db-&gt;create()){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;error($db-&gt;getError());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$username&nbsp;=&nbsp;$db-&gt;username;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$uid&nbsp;=&nbsp;$db-&gt;add())&nbsp;$this-&gt;error(&#39;注册失败，请重试....&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session(&#39;uid&#39;,$uid);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session(&#39;username&#39;,$username);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;success(&#39;注册成功&#39;,__APP__);
&nbsp;&nbsp;&nbsp;&nbsp;}</pre><p>&nbsp;使用TP字段映射，自动验证，自动填充。完成PHP端的验证操作</p><pre class="brush:php;toolbar:false">&lt;?php
/**
&nbsp;*&nbsp;用户表操作模型
&nbsp;*/
class&nbsp;UserModel&nbsp;extends&nbsp;Model{
&nbsp;&nbsp;&nbsp;&nbsp;//字段映射
&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;$_map&nbsp;=&nbsp;array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;pwd&#39;&nbsp;=&gt;&nbsp;&#39;password&#39;,
&nbsp;&nbsp;&nbsp;&nbsp;);
&nbsp;&nbsp;&nbsp;&nbsp;//自动验证
&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;$_validate&nbsp;=&nbsp;array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;account&#39;,&#39;require&#39;,&#39;帐号不能为空&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;account&#39;,&#39;/^[a-zA-Z]\w{6,19}$/s&#39;,&#39;帐号格式不正确&#39;,1,&#39;regex&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;account&#39;,&#39;&#39;,&#39;帐号已存在&#39;,1,&#39;unique&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;username&#39;,&#39;require&#39;,&#39;用户名不能为空&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;username&#39;,&#39;/^[\x80-\xff\w]{2,14}$/s&#39;,&#39;用户名格式不正确&#39;,1,&#39;regex&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;username&#39;,&#39;&#39;,&#39;用户名已存在&#39;,1,&#39;unique&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;password&#39;,&#39;require&#39;,&#39;密码不能为空&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;password&#39;,&#39;/^\w{6,20}$/s&#39;,&#39;密码格式不正确&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;pwded&#39;,&#39;password&#39;,&#39;两次密码不一致&#39;,1,&#39;confirm&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;);
&nbsp;&nbsp;&nbsp;&nbsp;//自动填充
&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;$_auto&nbsp;=&nbsp;array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;password&#39;,&#39;md5&#39;,1,&#39;function&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;logintime&#39;,&#39;time&#39;,1,&#39;function&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;loginip&#39;,&#39;get_client_ip&#39;,1,&#39;function&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&#39;registime&#39;,&#39;time&#39;,1,&#39;function&#39;),
&nbsp;&nbsp;&nbsp;&nbsp;);
}</pre><p><br/></p>    </ul>
    <div class="keybq">
    <p><span>关键字词</span>：php端验证</p>
    
    </div>
    <div class="ad"> </div>
    <div class="nextinfo">
      <p>上一篇：<a href="/index/article/25.html">自定义模板引擎的基本原理</a></p>
      <p>下一篇：<a href="/index/article/35.html">小i机器人微信自动回复代码测试</a></p>
    </div>
    <div class="otherlink">
      <h2>相关文章</h2>
      <ul>
        <li><a href="/index/article/44.html" title="写了一个PHP框架">写了一个PHP框架</a></li><li><a href="/index/article/35.html" title="小i机器人微信自动回复代码测试">小i机器人微信自动回复代码测试</a></li><li><a href="/index/article/26.html" title="php端验证">php端验证</a></li><li><a href="/index/article/25.html" title="自定义模板引擎的基本原理">自定义模板引擎的基本原理</a></li><li><a href="/index/article/23.html" title="图像处理类（缩略图，裁剪，打水印）">图像处理类（缩略图，裁剪，打水印）</a></li><li><a href="/index/article/19.html" title="验证码类(练手)">验证码类(练手)</a></li>        
      </ul>
    </div>
  </div>
  <aside class="right">
    <div class="news" style="margin-top:10px;">
    <h3>
	<p>最新<span>文章</span></p>
</h3>
	<ul class="rank">
		<li><a href="/index/article/49.html" title="新版网站完成50%了，继续加油吧" >新版网站完成50%了，继续加油吧</a></li><li><a href="/index/article/48.html" title="【Laravel5教程】mac+apache+mysql配置多站点(一)" >【Laravel5教程】mac+apache+mysql配置多站点(一)</a></li><li><a href="/index/article/47.html" title="Laravel5.1配置" >Laravel5.1配置</a></li><li><a href="/index/article/46.html" title="laravel5.1安装" >laravel5.1安装</a></li><li><a href="/index/article/45.html" title="初探Laravel5" >初探Laravel5</a></li><li><a href="/index/article/44.html" title="写了一个PHP框架" >写了一个PHP框架</a></li><li><a href="/index/article/42.html" title="当遇到问题时应该怎样去处理？" >当遇到问题时应该怎样去处理？</a></li><li><a href="/index/article/41.html" title="我的近况和计划" >我的近况和计划</a></li>	</ul>
<h3 class="ph">
    <p>点击<span>排行</span></p>
</h3>
	<ul class="paih">
    	<li><a href="/index/article/31.html" title="关于网站限制ie10以下浏览器访问的探讨" >关于网站限制ie10以下浏览器访问的探讨</a></li><li><a href="/index/article/46.html" title="laravel5.1安装" >laravel5.1安装</a></li><li><a href="/index/article/47.html" title="Laravel5.1配置" >Laravel5.1配置</a></li><li><a href="/index/article/45.html" title="初探Laravel5" >初探Laravel5</a></li><li><a href="/index/article/41.html" title="我的近况和计划" >我的近况和计划</a></li>	</ul>
<h3 class="links">
	<p>友情<span>链接</span></p>
</h3>
	<ul class="website">
		<li><a href="http://www.vso8.com" target="_blank">v8视频</a></li><li><a href="http://www.huanyun.net.cn" target="_blank">焕云企业管理有限公司</a></li><li><a href="http://www.sinkuo.com" target="_blank">济宁网站建设</a></li>	</ul>    </div>  
    <!-- Baidu Button BEGIN -->
    <div id="bdshare" class="bdshare_t bds_tools_32 get-codes-bdshare"><a class="bds_tsina"></a><a class="bds_qzone"></a><a class="bds_tqq"></a><a class="bds_renren"></a><span class="bds_more"></span><a class="shareCount"></a></div>
    <script type="text/javascript" id="bdshare_js" data="type=tools&amp;uid=6574585" ></script> 
    <script type="text/javascript" id="bdshell_js"></script> 
    <script type="text/javascript">

document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000)
</script> 
    <!-- Baidu Button END -->   
    <a onclick="javascript:window.open('/Public/Index/images/weixin.jpg','a', 'height=600,width=600,status=no,toolbar=no,menubar=no,location=no,scrollbars=no');" class="weixin"> </a></aside> 
</article>
<footer>
  <p><a href="http://www.miitbeian.gov.cn/" target="_blank">Copyright © 2015 yanhai All Rights Reversed | 鲁ICP备15004472号-1</a> </p>
</footer>
<script src="/Public/Index/js/silder.js"></script>

<script type="text/javascript">
     if(typeof(Worker) === "undefined"){
     	$.get('/Public/Html5/html5.html', function(data){
			$('body').html(data);
		})
     }
</script>

</body>
</html>